home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Action Atoms [inaa] Example / atom0.c next >
Encoding:
Text File  |  1996-10-01  |  5.0 KB  |  164 lines  |  [TEXT/MPS ]

  1. //
  2. //    atom0.c
  3. //
  4. //        Demonstration of a format0 action atom and compatibility with
  5. //        Installer Engine 4.1.
  6. //
  7. //        Under Installer 4.0.3, a dialog is provided that allows the
  8. //        user to select the return value for the action atom. 
  9. //
  10. //        Scriptwriters should be aware that the return values
  11. //        and the actions that they invoke from the installer
  12. //        are different depending on which format of action atom
  13. //        is being used. 
  14. //
  15. //        NOTE: Displaying dialogs from within action atoms and other
  16. //        code resources is discouraged.  Installer scripts that
  17. //        display dialogs from within code resources will not work
  18. //        when running under Installer Engine 4.1.  This example shows
  19. //        you how you can write action atom code that will display a
  20. //        dialog under Installer 4.0.3 and still be compatible with
  21. //        Installer Engine 4.1.  For more information on script
  22. //        compatibility with Installer Engine 4.1 see the "Engine 4.1
  23. //        Compatiblity Issues" document in the Installer 4.1 folder of
  24. //        the Installer SDK.
  25. //
  26. //      Additionally, this example completely ignores good user
  27. //        interface design practices for the purpose of demonstrating the
  28. //      installer in regards to return values from an action atom.
  29. //
  30. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  31. //
  32.  
  33. #include <Traps.h>
  34. #include <Types.h>
  35. #include <dialogs.h>
  36.  
  37. // this line replaces #include "ActionAtomHeader.h" used in previous 4.0.3 action atoms
  38. #include "InstallerScript.h"
  39.  
  40. // this is needed for highlighting the default button in dialog
  41. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  42.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  43.  
  44. // NOTE: The name of this function 'ActionAtomFormat0' should
  45. // match that specified in the -m option for the line in the
  46. // makefile that compiles this action atom.
  47.  
  48. pascal Boolean ActionAtomFormat0( AAPBRecPtr atomRecPtr )
  49. {
  50.  
  51.     DialogPtr    theDialog;                    // for dialog
  52.     OSErr        theOSError = 0;                // for errors
  53.     
  54.     short        theItemHit;                    // gets user response from ModalDialog()
  55.     short        iType;                        // gets control type from GetDItem()
  56.     Handle        iHandle;                    // gets control handle from GetDItem()
  57.     Rect         iRect;                        // gets control rect from GetDItem()
  58.     
  59.     short        currRadioButton = 2;        // current selected radio button
  60.     short        gettingUserResponse = true;    // flag for while loop
  61.     
  62.     short        theStatus = 0;                // value to return from function
  63.  
  64.     // retrieve DLOG/DITL 128 from compiled resource script
  65.     theDialog = GetNewDialog( 128, nil, (WindowPtr) -1 );
  66.  
  67.     // Installer Engine 4.1 will indicate that a window cannot be displayed by
  68.     // patching GetNewDialog and returning NULL.
  69.     if( theDialog != NULL )                    
  70.     {
  71.         // We are running with Installer 4.0.3
  72.         // Display the dialog.
  73.  
  74.         // activate OK button when enter or return key is pressed
  75.         theOSError = SetDialogDefaultItem( theDialog, 1 );
  76.     
  77.         // set up the radio button group ( controls 2 - 3 )
  78.         GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
  79.         SetCtlValue( (ControlHandle) iHandle, 1 );    
  80.         
  81.         GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
  82.         SetCtlValue( (ControlHandle) iHandle, 0 );    
  83.             
  84.         // select the new dialog
  85.         SelectWindow( (WindowPtr) theDialog );
  86.         
  87.         // show the new dialog
  88.         ShowWindow( (WindowPtr) theDialog );
  89.         
  90.         // keep getting response from user until
  91.         // the OK is activated in the new dialog
  92.         gettingUserResponse = true;
  93.         while ( gettingUserResponse )
  94.             {
  95.             // get user selection from the new dialog
  96.             ModalDialog( nil, &theItemHit );
  97.             switch ( theItemHit )
  98.                 {
  99.                 // first control is the OK key
  100.                 case( 1 ) : 
  101.                             // exit loop
  102.                             gettingUserResponse = false;
  103.                             break;
  104.                             
  105.                 // all other controls in dialog are radio buttons
  106.                 default :     
  107.                             // continue with loop
  108.                             gettingUserResponse = true;
  109.                             
  110.                             // if the radio button selection changed
  111.                             if ( currRadioButton != theItemHit )
  112.                                 {
  113.                                 // turn previous radio button off
  114.                                 GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
  115.                                 SetCtlValue(  (ControlHandle) iHandle, 0 );    
  116.             
  117.                                 // turn current radio button on
  118.                                 GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
  119.                                 SetCtlValue(  (ControlHandle) iHandle, 1 );    
  120.             
  121.                                 // save current radio button choice
  122.                                 currRadioButton = theItemHit;
  123.                                 }
  124.                             break;
  125.                 }// switch
  126.     
  127.             }// while
  128.             
  129.                                 // get rid of the new dialog
  130.         DisposDialog( theDialog );
  131.     
  132.                                 // select a value to return from this function according to
  133.                                 // which radio button was selected in the dialog
  134.         switch ( currRadioButton )
  135.             {
  136.                                             // return false
  137.             case( 2 ) : theStatus = false;    // user selected to return 0
  138.                         break;
  139.                         
  140.                                             // return true
  141.             case( 3 ) : theStatus = true;    // user selected to return 1
  142.                         break;
  143.                         
  144.             }
  145.             
  146.         // return value selected by user in dialog
  147.         return( theStatus );
  148.  
  149.     }// if theDialog != NULL
  150.     else
  151.     {
  152.         // We are running under Installer Engine 4.1, which doesn't interact with user.
  153.         // Do default action here rather than trying to display a dialog.
  154.         // Let's say the default action for this example is to return true.
  155.         
  156.         return (true);
  157.     }
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.